import datetime

from django.db import models

# Create your models here.


class TimeCreateUpdate(models.Model):
    create_time = models.DateTimeField(default=datetime.datetime.now(), verbose_name="注冊日期")
    update_time = models.DateTimeField(default=datetime.datetime.now(), verbose_name="修改日期")


class Merchant(TimeCreateUpdate):
    merchant_name = models.CharField(max_length=50, verbose_name="商家名")
    merchant_img = models.CharField(max_length=500, null=True, verbose_name="商家logo")
    describe = models.CharField(max_length=500, null=True, verbose_name="商家描述")
    base_fare = models.IntegerField(null=True, verbose_name="起送费")

    class Meta:
        db_table = "tb_merchant"


class MerchantAddress(TimeCreateUpdate):
    address_merchant = models.CharField("商家地址", max_length=100, null=True)
    longitude_and_latitude = models.CharField(max_length=20, null=True, verbose_name="经纬度")
    merchantaddress_address = models.ForeignKey(Merchant, blank=True, on_delete=models.DO_NOTHING)


    class Meta:
        db_table = "tb_merchant_address"


class Classify(TimeCreateUpdate):
    classify_name = models.CharField(max_length=20, verbose_name="分类名")
    merchant_classify = models.ForeignKey(Merchant, blank=True, on_delete=models.DO_NOTHING)

    class Meta:
        db_table = "tb_classify"


class Variety(TimeCreateUpdate):
    variety_name = models.CharField(max_length=50, verbose_name="菜品", null=True)
    price = models.DecimalField(max_digits=7, decimal_places=2, verbose_name="价格", null=True)
    variety_img = models.CharField(max_length=500, null=True, verbose_name="图片")
    describe = models.CharField("简述", max_length=10, null=True)
    minute_describe = models.CharField("详细简述", max_length=100, null=True)

    class Meta:
        db_table = "tb_variety"


class SetMeal(TimeCreateUpdate):
    set_meal_name = models.CharField("套餐名", null=True, max_length=20)

    class Meta:
        db_table = "tb_set_meal"


class User(TimeCreateUpdate):
    username = models.CharField(max_length=50, verbose_name="用户名", unique=True)
    user_mobile = models.CharField(max_length=11, verbose_name="用户手机号")
    user_password = models.CharField(max_length=100, verbose_name="用户密码")
    user_identity_card = models.CharField(max_length=18, verbose_name="用戶身份證號碼", null=True)
    describe = models.CharField(max_length=500, null=True, verbose_name="用户描述")
    user_img = models.CharField(max_length=500, verbose_name="用戶頭像", null=True)
    user_if = models.BooleanField(default=0, verbose_name="用户开关,0可以购买，1不可以")
    merchant_if = models.BooleanField(default=0, verbose_name="商家开关,0不是，1是")
    horseman_if = models.BooleanField(default=0, verbose_name="骑手开关,0不是，1是")
    staff_jurisdiction = models.CharField(max_length=50, null=True, verbose_name="用户开关,0可以购买，1不可以")
    user_merchant = models.OneToOneField(Merchant, on_delete=models.DO_NOTHING, blank=True)

    class Meta:
        db_table = "tb_user"


class Address(TimeCreateUpdate):
    address_name = models.CharField(max_length=100, verbose_name="地址")
    longitude_and_latitude = models.CharField(max_length=20, null=True, verbose_name="经纬度")
    label = models.CharField(max_length=50, verbose_name="标签", null=True)
    user_address = models.ForeignKey(User, blank=True, on_delete=models.DO_NOTHING)

    class Meta:
        db_table = "tb_address"


class Horseman(TimeCreateUpdate):
    horseman_name = models.CharField(max_length=50, verbose_name="骑手名")
    horseman_img = models.CharField(max_length=500, null=True, verbose_name="骑手头像")
    describe = models.CharField(max_length=500, null=True, verbose_name="骑手描述")
    leisure_if = models.BooleanField(default=0, verbose_name="是否空闲，0空闲，1送单中")

    class Meta:
        db_table = "tb_horseman"


class Order(TimeCreateUpdate):
    order_number = models.CharField(primary_key=True, verbose_name="订单号", max_length=250)
    state = models.IntegerField(default=0, verbose_name="0待支付， 1待派送， 2派送中， 3已完成")
    total_prices = models.IntegerField(default=0, verbose_name="总价")
    type_of_payment = models.BooleanField(null=True, verbose_name="0vx, 1zfb")
    remark = models.CharField(max_length=100, verbose_name="备注", null=True)

    user_order = models.ForeignKey(User, blank=True, on_delete=models.DO_NOTHING)
    merchant_order = models.ForeignKey(Merchant, blank=True, on_delete=models.DO_NOTHING)
    horseman_order = models.ForeignKey(Horseman, blank=True, on_delete=models.DO_NOTHING)

    class Meta:
        db_table = "tb_order"


class Orders_For_Goods(TimeCreateUpdate):
    variety_orders_for_goods = models.ForeignKey(Variety, blank=True, on_delete=models.DO_NOTHING)
    num = models.IntegerField(default=1, verbose_name="数量")
    price = models.DecimalField(max_digits=7, decimal_places=2, verbose_name="总价")
    order_orders_for_goods = models.ForeignKey(Order, blank=True, on_delete=models.DO_NOTHING)

    class Meta:
        db_table = "tb_orders_for_goods"


class ShoppingTrolley(TimeCreateUpdate):
    variety_shopping_trolley = models.ForeignKey(Variety, blank=True, on_delete=models.DO_NOTHING)
    num = models.IntegerField("数量", default=1)
    user_shopping_trolley = models.ForeignKey(User, blank=True, on_delete=models.DO_NOTHING)
    merchant_shopping_trolley = models.ForeignKey(Merchant, blank=True, on_delete=models.DO_NOTHING)
    total_price = models.DecimalField("总价", max_digits=7, decimal_places=2)

    class Meta:
        db_table = "tb_shopping_trolley"


class Meal_Dishes(TimeCreateUpdate):
    set_meal_meal_dishes = models.ForeignKey(SetMeal, blank=True, on_delete=models.DO_NOTHING)
    variety_meal_dishes = models.ForeignKey(Variety, blank=True, on_delete=models.DO_NOTHING)
    variety_num = models.IntegerField("菜品数量", null=True)
    price = models.DecimalField("价格", max_digits=7, decimal_places=2)
    classify_meal_dishes = models.ForeignKey(Classify, blank=True, on_delete=models.DO_NOTHING)

    class Meta:
        db_table = "tb_meal_dishes"


class Taste(TimeCreateUpdate):
    taste_name = models.CharField("口味名", max_length=10, null=True)

    class Meta:
        db_table = "tb_taste"


class Taste_Food(TimeCreateUpdate):
    taste_taste_food = models.ForeignKey(Taste, blank=True, on_delete=models.DO_NOTHING)
    variety_taste_food = models.ForeignKey(Variety, blank=True, on_delete=models.DO_NOTHING)
    the_specific_taste = models.CharField("具体口味", max_length=10, null=True)

    class Meta:
        db_table = "tb_taste_food"


